package com.xiaohe66.web.gateway.http.birth;

import com.xiaohe66.common.value.R;
import com.xiaohe66.web.application.birth.BirthdayAppService;
import com.xiaohe66.web.application.birth.bo.BirthdayListBo;
import com.xiaohe66.web.application.birth.bo.BirthdaySaveBo;
import com.xiaohe66.web.application.birth.result.BirthdayResult;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xiaohe
 * @since 2023.07.19 15:24
 */
@RestController
@RequestMapping("/birthday")
@RequiredArgsConstructor
public class BirthdayController {

    private final BirthdayAppService birthdayAppService;

    @PostMapping
    public R<BirthdayResult> save(@RequestBody BirthdaySaveBo bo) {
        return R.ok(birthdayAppService.save(bo));
    }

    @DeleteMapping("/{id}")
    public R<BirthdayResult> save(@PathVariable Long id) {
        birthdayAppService.delete(id);
        return R.ok();
    }

    @GetMapping()
    public R<List<BirthdayResult>> list(BirthdayListBo bo) {
        return R.ok(birthdayAppService.list(bo));
    }

}
